//
//  DetailCollectViewController.m
//  ReadMoon
//
//  Created by 殷殷明静 on 16/9/27.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "DetailCollectViewController.h"
#import "ContentTableViewCell.h"
#import "YMJMacro_h.h"
#import "UIView+YMJ_view.h"
#import "UIImageView+WebCache.h"
#import "AFNetworking.h"
#import "DetailModel.h"

#import "SelfSizeTool.h"
#import "MoreImageCollectionCollectionViewCell.h"
#import "RelevantFirstVC.h"
#import "SelfSizeTool.h"
#import "YMJEffectView.h"
#define COLOR [UIColor colorWithRed: 37 / 255.0 green:37 / 255.0 blue:37 / 255.0 alpha:100];
#define COLOR_TIP [UIColor colorWithRed:152 / 256.0 green:152 / 256.0 blue:152 / 256.0 alpha:1]
@interface DetailCollectViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,YMJEffectViewDelegate>
@property (nonatomic, strong) NSDictionary *dic;
@property (nonatomic, strong) NSMutableArray *imageArray;
@property (nonatomic, strong) NSMutableArray *moreArray;
@property (nonatomic, strong) UIButton *backBtn;
@property (nonatomic, strong) UIButton *shareBtn;
@property (nonatomic, strong) UIScrollView *bottomScrollView;
@property (nonatomic, strong) UIScrollView *zoomScrollView;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UICollectionView *collect;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, assign) CGFloat lastContentOffSet;
@property (nonatomic, strong) UIImageView *placeHolderView;
@property (nonatomic, strong) YMJEffectView *effectView;
@property (nonatomic, assign) BOOL isRestore;

@end

@implementation DetailCollectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = COLOR
    self.edgesForExtendedLayout = 0;
    [self initNavigationLeftButton];
    [self createData];
}
- (void)createData {
    _placeHolderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imagePlaceHolder"]];
    _placeHolderView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 - 64);
    [self.view addSubview:_placeHolderView];
    /*请求数据*/
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
    // 请求头
    [manager.requestSerializer setValue:@"Dalvik/1.6.0 (Linux; U; Android 4.2.1; R823T Build/JOP40D) Liuda/2.2.0 (agent:s;channel:360;credential:e1MxMDEwMDAxMDF9LXsjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIzg2MzMzMTAyODY3NDU0Mn0teyMjIyMjIyMxNDczMTU1OTc5ODA3LTQzNTkzYTY2M2R9QDE0NzI0MTc2MzEzMDE=;deviceId:863331028674542;osTypeId:01;detailInfo:android;simTypeId:01;netTypeId:01;deviceTypeId:01;osVersion:4.2.1;idfa:null)" forHTTPHeaderField:@"User-Agent"];
    [manager.requestSerializer setValue:@"api.9liuda.com" forHTTPHeaderField:@"Host"];
    [manager.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
    NSString *URL = _detailLink;
    [manager GET:URL parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        _dic = responseObject;
        DetailModel *detMo = [DetailModel modelWithDic:_dic];
        _imageArray = [NSMutableArray arrayWithArray:detMo.data.newsImageInfoList];
        
        for (int i = 0; i <_imageArray.count; i++) {
            NewsImageInfo *info = _imageArray[i];
            NSLog(@"%@",info.url);
        }
//        _moreArray = [NSMutableArray arrayWithArray:detailModel.data.atlasRelevantDTOCollection];
        if (_imageArray.count != 0) {
//            [self createBottomScrollerView];
//            [self createContentTableView];
//            [self createCollectionView];
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
    
}

// 自定义导航栏样式
- (void)initNavigationLeftButton {
    _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //    _backBtn.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_backBtn];
    _backBtn.frame = CGRectMake(20, 20, 20, 20);
    [_backBtn setBackgroundImage:[UIImage imageNamed:@"Icon_jiantou"] forState:0];
    [_backBtn addTarget:self action:@selector(backToLoginAndRegisterViewController) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_backBtn];
    // 分享
    _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:_shareBtn];
    _shareBtn.frame = CGRectMake(20, 20, 20, 20);
    [_shareBtn setBackgroundImage:[UIImage imageNamed:@"shengluehaow"] forState:0];
    [_shareBtn addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_shareBtn];
}
// pop返回
- (void)backToLoginAndRegisterViewController {
    [self.navigationController popViewControllerAnimated:YES];
}
// 自定义导航栏shadowImage的横线
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"balckNavcBar"] forBarMetrics:0];    
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:0];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
